var id = $("#id").val();
var fCode = $("#fCode").val();
var fStockID = $("#fStockID").val();
var fStockName = $("#fStockName").val();
var fApplyID = $("#fApplyID").val();
var flagss = $("#flagss").val();
/*
 * @Description: 预加载
 * @param : 
 */
$(function (){
	var URL,data = {},flag = 1;
	$("#headTitle").text(fStockName+"领料单");
	
	if(fCode !="" && id == "" && fApplyID ==""){
		URL = pathUrl("dispatch/findApplyItemEntry.action");
		data.fCode = fCode;
		data.fStockID = fStockID;
		flag = 1;
	}else if(fCode =="" && id =="" && fApplyID !=""){
		URL = pathUrl("dispatch/findApplyItemEntry.action");
		data.fApplyID = fApplyID;
		data.fStockID = fStockID;
		flag = 1;
	}else{
		URL = pathUrl("merge/findByMergeEntry.action");
		data.id = id;
		data.fStockID = fStockID;
		flag = 2;
	}
	data.row = 100000;
	$.ajax({
		url:URL,
		type:'POST',
		dataType:'JSON',
		async : false,
		data:data,
		success:function(data){
			console.log(data)
			var hide = "none",MCodeHide = "";
			if(flag == 1){
				hide = "";
				
			}
			$(".headinger").qrcode({
				width: 80,
				height: 80,
				correctLevel : 3,
				text: data.id
			});
			if(fStockID == 18290 || fStockID == 50140){
				MCodeHide = "none";
			}
			
			$("#dataset").text(data.dataset);
			var head = "<tr><th style='width:40px;'>序号</th><th style=''>物料代码</th><th>物料名称</th><th style=''>规格型号</th><th style='display:"+MCodeHide+"'>助记码</th><th style=''>应发数</th><th style=''>库存</th></tr>";
//			var head = "<tr><th style='width:40px;'>序号</th><th style=''>物料代码</th><th>物料名称</th><th style=''>规格型号</th><th style='width:50px;'>单位</th><th style='display:"+hide+"'>单位用量</th><th style=''>应发数</th><th style=''>库存</th></tr>";
			var body = "";
			for(var x=0;x<data.rows.length;x++){
				var fUnitQty;
				if(flag == 1){
					fUnitQty = data.rows[x].fAmount;
				}else{
					fUnitQty = data.rows[x].fUnitQty;
				}
				body +="<tr><td>"+ (x+1) +"</td><td class='left'>" + data.rows[x].fNumber + "</td><td class='left'>" + data.rows[x].fName +"</td><td class='left'>" + data.rows[x].fModel +"</td><td class='left' style='display:"+MCodeHide+"'>"+ data.rows[x].mcode +"</td><td>"+ data.rows[x].fQty +"</td><td style='white-space:nowrap;'>"+ data.rows[x].fStockQty +"</td></tr>";
//				body +="<tr><td>"+ (x+1) +"</td><td class='left'>" + data.rows[x].fNumber + "</td><td class='left'>" + data.rows[x].fName +"</td><td class='left'>" + data.rows[x].fModel +"</td><td>"+ data.rows[x].fUnit +"</td><td style='display:"+hide+"'>"+ fUnitQty +"</td><td>"+ data.rows[x].fQty +"</td><td>"+ data.rows[x].fStockQty +"</td></tr>";
//				body +="<tr><td>"+ x +"</td><td>" + x*655 + "</td><td class='left'>东方时尚是归属感大概的鬼地方的郭德纲地方的发生的发生规定刚发的规定规定发给电饭锅的</td><td>"+ x*10 +"</td></tr>";
			}
			$("#listTable").html(head+body);
		}
	});
	setTimeout(function(){
		print();
	}, 500);
});

/*
 * @Description: 打印
 * @param :
 */
function print() {
	var canvas=document.getElementsByTagName("canvas")[0];
	var dataURL = canvas.toDataURL("image/png");
	var img = '<img src="'+dataURL+'"></img>';
	$(".headinger").html(img);
	$(".row").print({
		deferred: $.Deferred().done(function() { 
			window.close(); 
		})//打印完后自动关闭打印页面
	});
}